﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace DoAn_BumTruong_DesignPattern
{
    class MenuProxy : Abstract
    {
        MenuController _mnctrl;
        public List<Menus> ListAll()
        {
            if (_mnctrl == null)
            {
                _mnctrl = new MenuController();
            }
            return _mnctrl.SelectAll();
        }
        //Signle
        public Menus SingleMenu(string menuID)
        {
            if (_mnctrl == null)
            {
                _mnctrl = new MenuController();
            }
            return _mnctrl.Single(menuID);
        }
        //Select Menucha
        public List<Menus> SelectParentID()
        {
            if (_mnctrl == null)
            {
                _mnctrl = new MenuController();
            }
            return _mnctrl.SelectParentID();
        }
        //Select By MenuCon
        public List<Menus> SelectParentIDChidren()
        {
            if (_mnctrl == null)
            {
                _mnctrl = new MenuController();
            }
            return _mnctrl.SelectParentIDChidren();
        }
        //MenuType
        public List<Menus> GetMenuRightTop(string menutype)
        {
            if (_mnctrl == null)
            {
                _mnctrl = new MenuController();
            }
            return _mnctrl.GetMenuRightTop(menutype);
        }
        //MenuPaging
        public List<Menus> Paging(string page, out int howManyPage)
        {
            if (_mnctrl == null)
            {
                _mnctrl = new MenuController();
            }
            return _mnctrl.Paging(page, out howManyPage);
        }

        public override bool Add(object o)
        {
            try
            {
                if (_mnctrl == null)
                    _mnctrl = new MenuController();
                return _mnctrl.Add(o);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public override bool Delete(object o)
        {
            try
            {
                if (_mnctrl == null)
                    _mnctrl = new MenuController();
                return _mnctrl.Delete(o);
            }
            catch (Exception)
            {
                throw;
            }
        }

        public override bool Update(object o)
        {
            try
            {
                if (_mnctrl == null)
                    _mnctrl = new MenuController();
                return _mnctrl.Update(o);
            }
            catch (Exception)
            {
                throw;
            }
        }

        //Update Active
        public bool UpdateActive(int id, bool state)
        {
            try
            {
                if (_mnctrl == null)
                    _mnctrl = new MenuController();
                return _mnctrl.UpdateActive(id, state);
            }
            catch (Exception)
            {
                throw;
            }
        }

        //Update MenuType
        public bool UpdateMenuType(int id, int type)
        {
            try
            {
                if (_mnctrl == null)
                    _mnctrl = new MenuController();
                return _mnctrl.UpdateMenuType(id, type);
            }
            catch (Exception)
            {
                throw;
            }
        }

        //Update OrderNo
        public bool UpdateOrderNo(int id, int orderNo)
        {
            try
            {
                if (_mnctrl == null)
                    _mnctrl = new MenuController();
                return _mnctrl.UpdateOrderNo(id, orderNo);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}